package com.tequila.bops.controller;

import com.tequila.core.service.AnaService;
import com.tequila.domain.entity.Ana;
import com.tequila.domain.enums.StateEnum;
import com.tequila.domain.query.AnaQuery;
import fe.core.ApiResponse;
import fe.core.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/ana")
public class AnaController {

    @Resource
    private AnaService anaService;

    @RequestMapping("/queryPageListByParam")
    public ApiResponse queryPageListByParam(AnaQuery query) {
        return ApiResponse.successApiResponse().withData(anaService.queryPageListByParam(query));
    }

    @RequestMapping("/queryById")
    public ApiResponse queryById(Long id) {
        return ApiResponse.successApiResponse().withData(anaService.queryById(id));
    }

    @RequestMapping("/save")
    public ApiResponse save(Ana entity) {
        return ApiResponse.successApiResponse().withData(anaService.save(entity));
    }

    @RequestMapping("/updateState")
    public ApiResponse updateState(Long id,String state) {
        Assert.assertNotNull(id,"id不能为空!");
        Assert.assertNotNull(state,"state不能为空!");
        Assert.assertNotNull(StateEnum.fromCode(state),"state错误!");
        Ana ana = new Ana();
        ana.setId(id);
        ana.setState(state);
        return ApiResponse.successApiResponse().withData(anaService.updateSelectiveById(ana));
    }

    @RequestMapping("/update")
    public ApiResponse update(Ana entity) {
        return ApiResponse.successApiResponse().withData(anaService.updateSelectiveById(entity));
    }
}
